package test4;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class ClientDemo {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        while (true) {
            Socket socket = new Socket("127.0.0.1", 8888);
//            输入
            OutputStream os = socket.getOutputStream();
            System.out.println("客户端-请发送:");
            String send = sc.next();
            os.write(send.getBytes());
            os.flush();
            if ("exit".equalsIgnoreCase(send)){
                socket.close();
                break;
            }
            socket.shutdownOutput();

            InputStream is = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String line;
            while ((line = br.readLine()) != null) {
                System.out.print("服务端-回复: ");
                System.out.println(line);
            }
            socket.shutdownInput();
        }
//        socket.close();
    }
}
